package cn.lsq.org.service.impl;

import cn.lsq.basic.utils.PageList;
import cn.lsq.org.domain.Employee;
import cn.lsq.org.mapper.EmployeeMapper;
import cn.lsq.org.query.EmployeeQuery;
import cn.lsq.org.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;
    @Override
    public List<Employee> loadAll() {
        return employeeMapper.loadAll();
    }

    @Override
    public Employee loadById(Long id) {
        return employeeMapper.loadById(id);
    }
    @Transactional
    @Override
    public void save(Employee employee) {
        employeeMapper.save(employee);
    }
    @Transactional
    @Override
    public void remove(Long id) {
        employeeMapper.remove(id);
    }
    @Transactional
    @Override
    public void update(Employee employee) {
        employeeMapper.update(employee);
    }

    @Override
    public PageList<Employee> queryPage(EmployeeQuery employeeQuery) {
        Long count = employeeMapper.queryCount(employeeQuery);
        if (count == 0){
            return new PageList<>();
        }
        List<Employee> employees = employeeMapper.queryData(employeeQuery);
        return new PageList<Employee>(count,employees);
    }
    @Override
    public void patchDelete(Long[] ids) {
        employeeMapper.patchDelete(ids);
    }
}
